package com.aba.hos.dao.impl;



import com.aba.hos.admin.Admin;
import com.aba.hos.dao.AdminDao;
import com.aba.hos.utils.BaseDao;

import java.sql.SQLException;
import java.util.List;

public class AdminDaoImpl extends BaseDao<Admin> implements AdminDao {

    @Override
    public int addAdmin(Admin admin)  throws SQLException{
        return this.update("INSERT INTO hos.admin (adminId, username, password, name, position, role, contactInfo) VALUES (?, ?, ?, ?, ?, ?)",
                admin.getAdminId(), admin.getUsername(), admin.getPassword(), admin.getName(), admin.getPosition(), admin.getRole(), admin.getContactInfo()
        );
    }

    @Override
    public int deleteAdminId(Integer id) throws SQLException {
        return this.update("delete from hos.admin where id = ?" , id);
    }

    @Override
    public int updateAdminName(Admin admin) throws SQLException {
        return this.update("update hos.admin set name=? where id = ?",
                admin.getName(),admin.getId()
        );
    }

    @Override
    public int updateAdminDoc(String id, String name, String position) throws SQLException {
        return this.update("update hos.admin set name=?,position=? where id = ?",
                name,position,id
        );
    }

    public int updateAdminPassword(Admin admin) throws SQLException {
        return this.update("update hos.admin set password=? where id = ?",
                admin.getPassword(),admin.getId()
        );
    }


    @Override
    public Admin queryAdminById(Integer id) throws SQLException {
        return this.getBean("select id, adminId, username, password, name, contactInfo, role, position from hos.admin where id = ?" , id);
    }

    @Override
    public Admin queryAdminByName(String name) throws SQLException {
        return this.getBean("select id, adminId, username, password, name, contactInfo, role, position from hos.admin where bucket_name = ?" , name);
    }

    @Override
    public List<Admin> queryAdmin() throws SQLException {
        return this.getBeanList("select id, adminId, username, password, name, contactInfo, role, position from hos.admin order by id asc");
    }

    @Override
    public List<Admin> queryAdminRole(String role) throws SQLException {
        return this.getBeanList("select id, adminId, username, password, name, contactInfo, role, position from hos.admin where role = ?" , role);
    }

    @Override
    public Admin queryAdminLimitOne() throws SQLException {
        return this.getBean("SELECT id, adminId, username, password, name, contactInfo, role, position FROM hos.admin ORDER BY id DESC LIMIT 1");
    }


}
